package com.study.shengsiyuan.example04;

import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.timeout.IdleStateEvent;

public class MyHeartbeatServerHandler extends ChannelInboundHandlerAdapter {
	//事件触发器
	@Override
	public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
		Channel channel = ctx.channel();
		if(evt instanceof IdleStateEvent) {
			IdleStateEvent event = (IdleStateEvent)evt;
			String eventType =null;
			switch (event.state()) {
				case  READER_IDLE:
					eventType ="读空闲";
					break;
				case  WRITER_IDLE:
					eventType ="写空闲";
					break;
				case  ALL_IDLE:
					eventType ="读写空闲";
					break;
			}
			System.out.println(channel.remoteAddress()+"的超时事件 : "+ eventType);
			channel.close();
		}

	}
}
